const Router = require('koa-router')
const newPage = new Router()
const {
  default: runCmd
} = require("../serverUtils/runCmd");
newPage.post('/', async (ctx, next) => {
  const params = ctx.req;
  // 创建新页面
  try {
    const res = await runCmd(`umi g1 page ${params.pageName}/index --less --typescript`);
    await next();
    ctx.body = {
      success: true,
      stdout: res.stdout
    };
  } catch (error) {
    await next();
    ctx.body = {
      success: false,
      stdout: error.stderr
    }
  }
});
module.exports = newPage;
